<?php
namespace App\Http\Controllers\Admin;

use App\Model\CorpMaster;
use App\Model\GoodsPrice;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Cookie;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Config;
use App\Model\UserModel;
use SplFileObject;

class SelectCorpController extends Controller
{

    function index(Request $request)
    {
      try{
            $auth = cookie::get('auth');

            if ($auth == Config::get('const.adrojapan')) {
                // 画面表示
            } elseif ($auth == Config::get('const.authAdmin')) {
                return redirect("admin/shoplist");
            } else {
                return redirect('login');
            }
            $corpMaster = new CorpMaster();

            $corpInfo = $corpMaster->getCorpMaster();

            return view('admin.select_corp', array(
                'corpInfos' => $corpInfo
            ));
        }catch (\Exception $e){
            \Log::error($e->getFile()." Line:".$e->getLine()." Msg:".$e->getMessage());
        }
    }

    function indexPrice(Request $request)
    {
        try{
            $corpMaster = new CorpMaster();

            $corpInfo = $corpMaster->getCorpMaster();

            return view('admin.select_corp_price', array(
                'corpInfos' => $corpInfo
            ));
        }catch (\Exception $e){
            \Log::error($e->getFile()." Line:".$e->getLine()." Msg:".$e->getMessage());
        }
    }

    function goto_home(Request $request)
    {
      try{
            $corp_id = $request->input('corp_id', '');
            Cookie::queue('sel_corp_id', $corp_id, Config::get('const.CookieExpire', 60 * 24 * 7));
            return redirect("admin/home");
          }catch (\Exception $e){
            \Log::error($e->getFile()." Line:".$e->getLine()." Msg:".$e->getMessage());
        }
    }
    function goto_price(Request $request)
    {
        try{
            $corp_id = $request->input('corp_id', '');
            Cookie::queue('price_sel_corp_id', $corp_id, Config::get('const.CookieExpire', 60 * 24 * 7));

            $goodsPrice = new GoodsPrice();
            $priceData = $goodsPrice->getGoodsPriceByCorpId($corp_id);
            return view('admin.goods_pricelist', array(
                'priceData' => $priceData
            ));
        }catch (\Exception $e){
            \Log::error($e->getFile()." Line:".$e->getLine()." Msg:".$e->getMessage());
        }
    }
}
